﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using G.Model;
using G.Runtime;

namespace G.Runtime
{
    public class GameGlobals
    {
        public delegate void MessageHandler(string message);
        public event MessageHandler MessageEvent;
        
        private readonly GameSpace _Game;
        private readonly GameGlobalDef _GameGlobalDef;
        private readonly GameValueDefs _GameValueDefs;
        private readonly GameEventDefs _GameEventDefs;
        private readonly GameEvents _Events = new GameEvents();
        private readonly GameValues _GameValues = new GameValues();
        private readonly GameImages _TopImages;

        public GameGlobals(GameGlobalDef pGameGlobalDef, GameSpace pGame)
        {
            _Game = pGame;
            _GameGlobalDef = pGameGlobalDef;
            _TopImages = new GameImages(_Game);

            _GameValueDefs = pGameGlobalDef.GameValueDefs;
            foreach (GameValueDef def in _GameValueDefs)
            {
                _GameValues.Add(def);
            }

            _GameEventDefs = pGameGlobalDef.GameEventDefs;
            foreach (GameEventDef def in _GameEventDefs)
            {
                GameEvent v = new GameEvent(_Game, def);
                if (!_Events.Contains(v))
                {
                    _Events.Add(v);
                }
            }
        }

        public GameSpace Game
        {
            get { return _Game; }
        }

        public GameValues Values
        {
            get { return _GameValues; }
        }

        public GameEvents Events
        {
            get { return _Events; }
        }

        public GameImages TopImages
        {
            get { return _TopImages; }
        }
        
        public void Turn()
        {
            GameEvent turn = _Events[Constants.END_OF_TURN];
            turn.FireInvoke();
        }
        
        public void FireMessage(string message)
        {
            if (MessageEvent != null)
            {
                MessageEvent(message);
            }
        }

    }
}
